
clear all

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1

global emily 1
global carolina 0

*********************
*Load Files*
*********************

*Carolina's Computer*
if $carolina ==1  {
cap cd "~\Dropbox\Carolina-Emily-Project\Data\Study"
global out "..\..\Results\"
}


if $emily ==1  {
*Emily's Computer*
cap cd "~/Dropbox/SourceContent/Data/Study"
global out "../../Results/"
global draftout "../../Draft/Figures/"
} 

*Note: Need to install grc1leg
cap ssc install grc1leg

*Robustness Versions*

*1. Base
global spec1covar0 		"$lasso0"
global spec1covar1 		"$lasso1"
global spec1restrict	""
global spec1out			"ln1_prob_index_"

*2. Remove Covariates
global spec2covar0 		""
global spec2covar1 		""
global spec2restrict	""
global spec2out			"ln1_prob_index_"

*3. Before Election
global spec3covar0 		"$lasso0"
global spec3covar1 		"$lasso1"
global spec3restrict	"& beforevote==1"
global spec3out			"ln1_prob_index_"

*4. Remove Duplicate Responders
global spec4covar0 		"$lasso0"
global spec4covar1 		"$lasso1"
global spec4restrict	"& numbersurveys==1"
global spec4out			"ln1_prob_index_"

*5. Log(Probability)
global spec5covar0 		"$lasso0"
global spec5covar1 		"$lasso1"
global spec5restrict	""
global spec5out			"ln_prob_index_"

*6. 5 option version
global spec6covar0 		"$lasso0"
global spec6covar1 		"$lasso1"
global spec6restrict	""
global spec6out			"ln1_prob5_index_"

*7. 14 question version
global spec7covar0 		"$lasso0"
global spec7covar1 		"$lasso1"
global spec7restrict	""
global spec7out			"ln1_prob14_index_"

*8. Unlogged Outcome
global spec8covar0 		"$lasso0"
global spec8covar1 		"$lasso1"
global spec8restrict	""
global spec8out			"prob_index_"

*Skip 9 For Now - Really Changes up Scale of Graph
*9. Standardized Unlogged Outcome
global spec9covar0 		"$lasso0"
global spec9covar1 		"$lasso1"
global spec9restrict	""
global spec9out			"probst_index_"

*10. Inverse Hyperbolic Sine
global spec10covar0 	"$lasso0"
global spec10covar1 	"$lasso1"
global spec10restrict	""
global spec10out		"ins_prob_index_"

*11. Anderson (2008) Weighted Index - Unlogged Outcome
global spec11covar0 	"$lasso0"
global spec11covar1 	"$lasso1"
global spec11restrict	""
global spec11out		"prob_anderson_"

*12. Anderson (2008) Weighted Index - Logged Outcome
global spec12covar0 	"$lasso0"
global spec12covar1 	"$lasso1"
global spec12restrict	""
global spec12out		"ln1_prob_anderson_"

*9. Standardized Unlogged Outcome
global spec13covar0 		"$lasso0"
global spec13covar1 		"$lasso1"
global spec13restrict	""
global spec13out			"probst_anderson_"

* Logit - Not looped

* Probit - Not looped

* Log Probability Version - Not looped*
	
	
*********************************
***Other Globals***
*********************************
	
global lasso0 hispanic age55_64 candidate16_hillary candidate16_other ///
	immlevel_decrease gun_lessstrict abortion_illegal tax_toohigh health_notgvt ///
	occ_twitter occ_buzzfeed trumpfan lebronfan taylorfan bgatesfan ///
	obamafan obama_neutral topissue_health 
	
global lasso1 black hispanic age35_44 age45_54 hsdegree ///
	candidate16_hillary immlevel_decrease immlevel_same ///
	gun_same gun_lessstrict abortion_partlegal abortion_illegal tax_toohigh ///
	health_neutral health_notgvt i.freq_nytimes ///
	daily_tv occ_tv daily_newspaper i.freq_fox week_breitbart ///
	daily_breitbart occ_buzzfeed ///
	lebron_neutral obamafan trump_neutral trumpfan west topissue_tax 

global message1 "Anti"
global message2 "Anti"
global message3 "Pro"
global message4 "Pro"

global source1 "Trump"
global source2 "Obama"
global source3 "Trump"
global source4 "Obama" 

global party0 "Republicans"
global party1 "Democrats"
global var0 "ln(Probability Anti-Immigrant + 1)"
global var1 "ln(Probability Pro-Immigrant + 1)"
global dir0 "anti"
global dir1 "pro"

global color1 "blue"
global color0 "red"

global label1a0 "{bf:Anti}	"
global label2a0 "{bf:Anti}	"
global label3a0 "{bf:Pro}	"
global label4a0 "{bf:Pro}	"
global label1b0 "{bf:Trump}	"
global label2b0 "{bf:Obama}	"
global label3b0 "{bf:Trump}	"
global label4b0 "{bf:Obama}	"

global width0 "3"
global width1 "2.25"

foreach x in a b {
foreach y in 1 2 3 4 {
	global label`y'`x'1 ""
}
}

**************************************************
*CREATE VARIABLES*
**************************************************

use 3_clean_data, replace

gen group1=treatment==5 | treatment==7 | treatment==0
gen group2=treatment==6 | treatment==8 | treatment==0
gen group3=treatment==1 | treatment==3 | treatment==0
gen group4=treatment==2 | treatment==4 | treatment==0

gen president=treatment==1 | treatment==2 | treatment==5 | treatment==6
gen actor=treatment==3 | treatment==4 | treatment==7 | treatment==8
gen turkey= treatment==9 | treatment==10
gen priming=turkey==1 | president==1
gen message=actor==1 | president==1

sum prob_index_anti if recruit==0 & treat==0, d
gen disc_index_anti=prob_index_anti>=r(p50)
	
sum prob_index_pro if recruit==1 & treat==0, d
gen disc_index_pro=prob_index_pro>=r(p50)

gen ins_prob_index_pro=ln(prob_index_pro+(prob_index_pro^2+1)^0.5)
gen ins_prob_index_anti=ln(prob_index_anti+(prob_index_anti^2+1)^0.5)


**************************************************
*CREATE PLOTS OF RESULTS*
**************************************************

**************************************************
*10A. Main Robustness Specifications*
**************************************************


preserve

foreach p in 0 1 {
	gen bm`p'=.
	gen um`p'=.
	gen lm`p'=.
	gen bms`p'=.
	gen ums`p'=.
	gen lms`p'=.
}


gen n=_n

foreach p in 0 1 {

local n=0
	
foreach y in 4 3 2 1 {

foreach s in 7 6 4 3 2 1 {
	
	local n=`n'+1
 
	*Regression for Coefficients*
	reg ${spec`s'out}${dir`p'} message president ${spec`s'covar`p'} ///
		if (group`y'==1) & recruit==`p' ${spec`s'restrict}, robust
	
	*Anonymous Message - Beta_m*
	replace bm`p' = _b[message] if n==`n'
	replace um`p' = _b[message]+1.96*_se[message] if n==`n'
	replace lm`p' = _b[message]-1.96*_se[message] if n==`n'

	*Persuasion - Beta_ms *	
	replace bms`p' = _b[president] if n==`n'
	replace ums`p' = _b[president]+1.96*_se[president] if n==`n'
	replace lms`p' = _b[president]-1.96*_se[president] if n==`n'
	
	*Anonymous Message - P(Dist)*
	reg ${spec`s'out}${dir`p'} ${spec`s'covar`p'} ///
		if (group`y'==1 & president==0) & recruit==`p' ${spec`s'restrict}, robust
	predict res, res
	gen g=0 if actor==0 & e(sample)==1
	replace g=1 if actor==1 & e(sample)==1
	ksmirnov res if e(sample), by(g)
	local dm`n'`p'=round(r(p)*10000)/10000
	local dm`n'`p': di %6.3f `dm`n'`p''
	drop g res
	
	*Persuasion - P(Dist)*
	reg ${spec`s'out}${dir`p'} ${spec`s'covar`p'} ///
		if (group`y'==1 & treat!=0) & recruit==`p' ${spec`s'restrict}, robust
	predict res, res
	gen g=0 if president==0 & e(sample)==1
	replace g=1 if president==1 & e(sample)==1
	ksmirnov res if e(sample), by(g)
	local dms`n'`p'=round(r(p)*10000)/10000
	local dms`n'`p': di %6.3f `dms`n'`p''
	drop g res

	}
	
	local n=`n'+1
	
}

replace n=. if n>27

foreach m in "m" "ms" {

# delimit ;
twoway	
	(rcap l`m'`p' u`m'`p' n if n==6 | n==13 | n==20 | n==27 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==6 | n==13 | n==20 | n==27, mcolor(black) )	
	(rcap l`m'`p' u`m'`p' n if n==5 | n==12 | n==19 | n==26 , horizontal lcolor(black)) 
	(scatter n b`m'`p' if n==5 | n==12 | n==19 | n==26, mcolor(black) msymbol(circle_hollow) )	
	(rcap l`m'`p' u`m'`p' n if n==4 | n==11 | n==18 | n==25 , horizontal lcolor(black)) 
	(scatter n b`m'`p' if n==4 | n==11 | n==18 | n==25 , mcolor(black) msymbol(square_hollow) )	
	(rcap l`m'`p' u`m'`p' n if n==3 | n==10 | n==17 | n==24 , horizontal lcolor(black)) 
	(scatter n b`m'`p' if n==3 | n==10 | n==17 | n==24 , mcolor(black) msymbol(diamond_hollow) )	
	(rcap l`m'`p' u`m'`p' n if n==2 | n==9 | n==16 | n==23 , horizontal lcolor(black)) 
	(scatter n b`m'`p' if n==2 | n==9 | n==16 | n==23 , mcolor(black) msymbol(triangle_hollow) )	
	(rcap l`m'`p' u`m'`p' n if n==1 | n==8 | n==15 | n==22 , horizontal lcolor(black)) 
	(scatter n b`m'`p' if n==1 | n==8 | n==15 | n==22 , mcolor(black) msymbol(X) )	
	, 
	xline(0, lcolor(black)) 
	ylabel(
	28	`" "{bf:P(Dist):}" "'
	27	`" "${label1a`p'}{it:`d`m'27`p''}" "'
	26	`" "${label1b`p'}{it:`d`m'26`p''}" "'
	25	`" "{it:`d`m'25`p''}" "'
	24	`" "{it:`d`m'24`p''}" "'
	23	`" "{it:`d`m'23`p''}" "'
	22	`" "{it:`d`m'22`p''}" "'
	21	" "
	20	`" "${label2a`p'}{it:`d`m'20`p''}" "'
	19	`" "${label2b`p'}{it:`d`m'19`p''}" "'
	18	`" "{it:`d`m'18`p''}" "'
	17	`" "{it:`d`m'17`p''}" "'
	16	`" "{it:`d`m'16`p''}" "'
	15	`" "{it:`d`m'15`p''}" "'
	14	" "
	13	`" "${label3a`p'}{it:`d`m'13`p''}" "'
	12	`" "${label3b`p'}{it:`d`m'12`p''}" "'
	11	`" "{it:`d`m'11`p''}" "'
	10	`" "{it:`d`m'10`p''}" "'
	9	`" "{it:`d`m'9`p''}" "'
	8	`" "{it:`d`m'8`p''}" "'
	7	" "
	6	`" "${label4a`p'}{it:`d`m'6`p''}" "'
	5	`" "${label4b`p'}{it:`d`m'5`p''}" "'
	4	`" "{it:`d`m'4`p''}" "'
	3	`" "{it:`d`m'3`p''}" "'
	2	`" "{it:`d`m'2`p''}" "'
	1	`" "{it:`d`m'1`p''}" "'
	, angle(0) labsize(small)) 
	xtitle(" " "{bf:${party`p'}}" "{it:${var`p'}}" " ")
	ytitle("")
	ylab(, nogrid)
	xlab(-0.03(0.015)0.03)
	graphregion(color(white)) 
	legend(order(2 "Base"  4 "Without Covariates" 
	6 "Before Election" 8 "No Duplicate Responders"
	10 "5 Option Version" 12 "14 Question Version") 
	rows(2) size(*0.75) symxsize(*0.4))
	ylabel(, tlength(0))
	saving("$out/`m'`p'.gph", replace)
	;
	# delimit cr
	
}
}

# delimit ;
grc1leg "$out/m0.gph" "$out/m1.gph", 
	ycommon xcommon legendfrom("$out/m0.gph")
	graphregion(color(white)) 
	imargin(-5.5 -5.5 -6 -12) scale(1.1) 
;
# delimit cr
graph export "$draftout/A5_Robustness_AnonymousMessage.eps", replace	

# delimit ;
grc1leg "$out/ms0.gph" "$out/ms1.gph", 
	ycommon xcommon legendfrom("$out/ms1.gph")
	graphregion(color(white))  
	imargin(-5.5 -5.5 -6 -12) scale(1.1) 
;
# delimit cr
graph export "$draftout/A5_Robustness_Persuasion.eps", replace	


restore


**************************************************
*10B. Robustness of Log Specification*
**************************************************

preserve

foreach p in 0 1 {
	gen bm`p'=.
	gen um`p'=.
	gen lm`p'=.
	gen bms`p'=.
	gen ums`p'=.
	gen lms`p'=.
}

gen n=_n

foreach p in 0 1 {

local n=0
	
foreach y in 4 3 2 1 {

foreach s in 8 10 5 1 {
	
	local n=`n'+1
 
	*Regression for Coefficients*
	reg ${spec`s'out}${dir`p'} message president ${spec`s'covar`p'} ///
		if (group`y'==1) & recruit==`p' ${spec`s'restrict}, robust
	
	*Anonymous Message - Beta_m*
	replace bm`p' = _b[message] if n==`n'
	replace um`p' = _b[message]+1.96*_se[message] if n==`n'
	replace lm`p' = _b[message]-1.96*_se[message] if n==`n'

	*Persuasion - Beta_ms *	
	replace bms`p' = _b[president] if n==`n'
	replace ums`p' = _b[president]+1.96*_se[president] if n==`n'
	replace lms`p' = _b[president]-1.96*_se[president] if n==`n'
	
	*Anonymous Message - P(Dist)*
	reg ${spec`s'out}${dir`p'} ${spec`s'covar`p'} ///
		if (group`y'==1 & president==0) & recruit==`p' ${spec`s'restrict}, robust
	predict res, res
	gen g=0 if actor==0 & e(sample)==1
	replace g=1 if actor==1 & e(sample)==1
	ksmirnov res if e(sample), by(g)
	local dm`n'`p'=round(r(p)*10000)/10000
	local dm`n'`p': di %6.3f `dm`n'`p''
	drop g res
	
	*Persuasion - P(Dist)*
	reg ${spec`s'out}${dir`p'} ${spec`s'covar`p'} ///
		if (group`y'==1 & treat!=0) & recruit==`p' ${spec`s'restrict}, robust
	predict res, res
	gen g=0 if president==0 & e(sample)==1
	replace g=1 if president==1 & e(sample)==1
	ksmirnov res if e(sample), by(g)
	local dms`n'`p'=round(r(p)*10000)/10000
	local dms`n'`p': di %6.3f `dms`n'`p''
	drop g res

	}
	
	local n=`n'+1
	
}

foreach m in "m" "ms" {

# delimit ;
twoway	
	(rcap l`m'`p' u`m'`p'  n if n==4 | n==9 | n==14 | n==19 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==4 | n==9 | n==14 | n==19 , mcolor(black) )	
	(rcap l`m'`p' u`m'`p' n if n==3 | n==8 | n==13 | n==18 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==3 | n==8 | n==13 | n==18 , mcolor(black) msymbol(circle_hollow) )	
	(rcap l`m'`p' u`m'`p'  n if n==2 | n==7 | n==12 | n==17 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==2 | n==7 | n==12 | n==17 , mcolor(black) msymbol(square_hollow) )	
	(rcap l`m'`p' u`m'`p'  n if n==1 | n==6 | n==11 | n==16 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==1 | n==6 | n==11 | n==16 , mcolor(black) msymbol(diamond_hollow) )	
	, 
	xline(0, lcolor(black)) 
	ylabel(
	20  "{bf:P(Dist):}" 
	19	`" "${label1a`p'}{it:`d`m'19`p''}" "'
	18	`" "${label1b`p'}{it:`d`m'18`p''}" "'
	17	`" "{it:`d`m'17`p''}" "'
	16	`" "{it:`d`m'16`p''}" "'
	15	" "
	14	`" "${label2a`p'}{it:`d`m'14`p''}" "'
	13	`" "${label2b`p'}{it:`d`m'13`p''}" "'
	12	`" "{it:`d`m'12`p''}" "'
	11	`" "{it:`d`m'11`p''}" "'
	10	" "
	9	`" "${label3a`p'}{it:`d`m'9`p''}" "'
	8	`" "${label3b`p'}{it:`d`m'8`p''}" "'
	7	`" "{it:`d`m'7`p''}" "'
	6	`" "{it:`d`m'6`p''}" "'
	5	" "
	4	`" "${label4a`p'}{it:`d`m'4`p''}" "'
	3	`" "${label4b`p'}{it:`d`m'3`p''}" "'
	2	`" "{it:`d`m'2`p''}" "'
	1	`" "{it:`d`m'1`p''}" "'
	, angle(0) labsize(small)) 
	xtitle(" " "{bf:${party`p'}}" "{it:${var`p'}}" " ")
	ytitle("")
	ylab(, nogrid)
	xlab(-0.08(0.04)0.08)
	graphregion(color(white)) 
	legend(order(2 "Base" "Log(Outcome+1)"  4 "Log(Outcome)" 
	6 "Inverse Hyperbolic Sine" 8 "Outcome" ) 
	rows(1) size(*0.75) symxsize(*0.4))
	ylabel(, tlength(0))
	saving("$out/`m'`p'.gph", replace)
	;
	# delimit cr
	
}
}

*xsize(${width`p'}) ysize(5) 
# delimit ;
grc1leg "$out/m0.gph" "$out/m1.gph", 
	ycommon xcommon legendfrom("$out/m0.gph")
	graphregion(color(white)) 
	imargin(-5.5 -5.5 -6 -7) scale(1.1) 
	;
# delimit cr
graph export "$draftout/A6_Robustness_AnonymousMessage.eps", replace	
*	xsize(9) ysize(9)


# delimit ;
grc1leg "$out/ms0.gph" "$out/ms1.gph", 
	ycommon xcommon legendfrom("$out/ms1.gph")
	graphregion(color(white)) 
	imargin(-5.5 -5.5 -6 -7) scale(1.1) 
	;
# delimit cr
graph export "$draftout/A6_Robustness_Persuasion.eps", replace	
*	xsize(9) ysize(9)


restore



*********************************************************************
*10C. Change in Probability: Log, Linear Probability, Logit & Probit*
*********************************************************************

preserve

foreach p in 0 1 {
	gen bm`p'=.
	gen um`p'=.
	gen lm`p'=.
	gen bms`p'=.
	gen ums`p'=.
	gen lms`p'=.
}

gen n=_n

foreach p in 0 1 {

local n=0
	
foreach y in 4 3 2 1 {

	*Probit & Logit Model*
	foreach z in "probit" "logit" {
	
	local n=`n'+1

	`z' disc_index_${dir`p'} i.message ${lasso`p'} ///
		if (group`y'==1 & president==0) & recruit==`p' , robust
	
	*Anonymous Message - Beta_m*
	margins r.message, atmeans post
	margins, coeflegend
	*Do in terms of Probabilities
	replace bm`p' = _b[r1vs0.message] if n==`n'
	*Use Delta Method for Confidence Intervals
	replace um`p' = _b[r1vs0.message]+1.96*_se[r1vs0.message] if n==`n'
	replace lm`p' = _b[r1vs0.message]-1.96*_se[r1vs0.message] if n==`n'
		
	`z' disc_index_${dir`p'} i.president ${lasso`p'} ///
		if (group`y'==1 & treat!=0) & recruit==`p' , robust
	
	*Persuasion - Beta_ms *	
	margins r.president, atmeans post
	margins, coeflegend
	*Do in terms of Probabilities
	replace bms`p' = _b[r1vs0.president] if n==`n'
	*Use Delta Method for Confidence Intervals
	replace ums`p' = _b[r1vs0.president]+1.96*_se[r1vs0.president] if n==`n'
	replace lms`p' = _b[r1vs0.president]-1.96*_se[r1vs0.president] if n==`n'
	
	}
 
	local n=`n'+1

	*Linear Probability Model*
	reg prob_index_${dir`p'} message president ${lasso`p'} ///
		if (group`y'==1) & recruit==`p', robust
	
	*Anonymous Message - Beta_m*
	replace bm`p' = _b[message] if n==`n'
	replace um`p' = _b[message]+1.96*_se[message] if n==`n'
	replace lm`p' = _b[message]-1.96*_se[message] if n==`n'
	*Persuasion - Beta_ms *	
	replace bms`p' = _b[president] if n==`n'
	replace ums`p' = _b[president]+1.96*_se[president] if n==`n'
	replace lms`p' = _b[president]-1.96*_se[president] if n==`n'
	
	local n=`n'+1

	*Base Model (ln(p+1)) - Probability Version*
	reg ln1_prob_index_${dir`p'} message president ${lasso`p'} ///
		if (group`y'==1) & recruit==`p' , robust
	*Do in terms of Probabilities
	sum prob_index_${dir`p'}
	local f=r(mean)
	*Use Delta Method for Confidence Intervals
	replace bm`p' = _b[message]*(`f'+1) if n==`n'
	replace um`p' = bm`p'+1.96*(`f'+1)*_se[message] if n==`n'
	replace lm`p' = bm`p'-1.96*(`f'+1)*_se[message] if n==`n'
	replace bms`p' = _b[president]*(`f'+1) if n==`n'
	replace ums`p' = bms`p'+1.96*(`f'+1)*_se[president] if n==`n'
	replace lms`p' = bms`p'-1.96*(`f'+1)*_se[president] if n==`n'

	local n=`n'+1
	
}	

foreach m in "m" "ms" {

# delimit ;
twoway	
	(rcap l`m'`p' u`m'`p'  n if n==4 | n==9 | n==14 | n==19 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==4 | n==9 | n==14 | n==19 , mcolor(black) )	
	(rcap l`m'`p' u`m'`p' n if n==3 | n==8 | n==13 | n==18 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==3 | n==8 | n==13 | n==18 , mcolor(black) msymbol(circle_hollow) )	
	(rcap l`m'`p' u`m'`p'  n if n==2 | n==7 | n==12 | n==17 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==2 | n==7 | n==12 | n==17 , mcolor(black) msymbol(square_hollow) )	
	(rcap l`m'`p' u`m'`p'  n if n==1 | n==6 | n==11 | n==16 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==1 | n==6 | n==11 | n==16 , mcolor(black) msymbol(diamond_hollow) )	
	, 
	xline(0, lcolor(black)) 
	ylabel(
	19	`" "${label1a`p'}" "'
	18	`" "${label1b`p'}" "'
	17	`" "" "'
	16	`" "" "'
	15	" "
	14	`" "${label2a`p'}" "'
	13	`" "${label2b`p'}" "'
	12	`" "" "'
	11	`" "" "'
	10	" "
	9	`" "${label3a`p'}" "'
	8	`" "${label3b`p'}" "'
	7	`" "" "'
	6	`" "" "'
	5	" "
	4	`" "${label4a`p'}" "'
	3	`" "${label4b`p'}" "'
	2	`" "" "'
	1	`" "" "'
	, angle(0) labsize(small)) 
	xtitle(" " "{bf:${party`p'}}" "{it:${var`p'}}" " ")
	ytitle("")
	ylab(, nogrid)
	xlab(-.2(0.05).15)
	graphregion(color(white)) 
	legend(order(2 "Base" "Log(Outcome+1)" 4 "Linear Probability" 6 "Logit" 8 "Probit")
	rows(1) size(*0.75) symxsize(*0.4))
	ylabel(, tlength(0))
	saving("$out/`m'`p'.gph", replace)
	;
	# delimit cr
	
}
}

# delimit ;
grc1leg "$out/m0.gph" "$out/m1.gph", 
	ycommon xcommon legendfrom("$out/m0.gph")
	graphregion(color(white)) 
	imargin(-3 -8 -6 -7) scale(1.1) 
	;
# delimit cr
graph export "$draftout/A8_Robustness_AnonymousMessage.eps", replace	


# delimit ;
grc1leg "$out/ms0.gph" "$out/ms1.gph", 
	ycommon xcommon legendfrom("$out/ms1.gph")
	graphregion(color(white)) 
	imargin(-3 -3 -6 -7) scale(1.1) 
	;
# delimit cr
graph export "$draftout/A8_Robustness_Persuasion.eps", replace	


restore


**************************************************
*10D. Standardized Indices - Not Log Adjusted*
**************************************************

preserve

global var0 "Standardized Probability Anti-Immigrant"
global var1 "Standardized Probability Pro-Immigrant"


foreach p in 0 1 {
	gen bm`p'=.
	gen um`p'=.
	gen lm`p'=.
	gen bms`p'=.
	gen ums`p'=.
	gen lms`p'=.
}

gen n=_n

foreach p in 0 1 {

local n=0
	
foreach y in 4 3 2 1 {

foreach s in 13 9 {
	
	local n=`n'+1
 
	*Regression for Coefficients*
	reg ${spec`s'out}${dir`p'} message president ${spec`s'covar`p'} ///
		if (group`y'==1) & recruit==`p' ${spec`s'restrict}, robust
	
	*Anonymous Message - Beta_m*
	replace bm`p' = _b[message] if n==`n'
	replace um`p' = _b[message]+1.96*_se[message] if n==`n'
	replace lm`p' = _b[message]-1.96*_se[message] if n==`n'

	*Persuasion - Beta_ms *	
	replace bms`p' = _b[president] if n==`n'
	replace ums`p' = _b[president]+1.96*_se[president] if n==`n'
	replace lms`p' = _b[president]-1.96*_se[president] if n==`n'
	
	*Anonymous Message - P(Dist)*
	reg ${spec`s'out}${dir`p'} ${spec`s'covar`p'} ///
		if (group`y'==1 & president==0) & recruit==`p' ${spec`s'restrict}, robust
	predict res, res
	gen g=0 if actor==0 & e(sample)==1
	replace g=1 if actor==1 & e(sample)==1
	ksmirnov res if e(sample), by(g)
	local dm`n'`p'=round(r(p)*10000)/10000
	local dm`n'`p': di %6.3f `dm`n'`p''
	drop g res
	
	*Persuasion - P(Dist)*
	reg ${spec`s'out}${dir`p'} ${spec`s'covar`p'} ///
		if (group`y'==1 & treat!=0) & recruit==`p' ${spec`s'restrict}, robust
	predict res, res
	gen g=0 if president==0 & e(sample)==1
	replace g=1 if president==1 & e(sample)==1
	ksmirnov res if e(sample), by(g)
	local dms`n'`p'=round(r(p)*10000)/10000
	local dms`n'`p': di %6.3f `dms`n'`p''
	drop g res

	}
	
	local n=`n'+1
	
}

foreach m in "m" "ms" {

# delimit ;
twoway	
	(rcap l`m'`p' u`m'`p'  n 	if n==2 | n==5 | n==8 | n==11 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  		if n==2 | n==5 | n==8 | n==11 , mcolor(black) )	
	(rcap l`m'`p' u`m'`p' n 	if n==1 | n==4 | n==7 | n==10 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  		if n==1 | n==4 | n==7 | n==10 , mcolor(black) msymbol(circle_hollow) )	
	, 
	xline(0, lcolor(black)) 
	ylabel(
	12  "{bf:P(Dist):}" 
	11	`" "${label1a`p'}{it:`d`m'11`p''}" "'
	10	`" "${label1b`p'}{it:`d`m'10`p''}" "'
	9	" "
	8	`" "${label2a`p'}{it:`d`m'8`p''}" "'
	7	`" "${label2b`p'}{it:`d`m'7`p''}" "'
	6	" "
	5	`" "${label3a`p'}{it:`d`m'5`p''}" "'
	4	`" "${label3b`p'}{it:`d`m'4`p''}" "'
	3	" "
	2	`" "${label4a`p'}{it:`d`m'2`p''}" "'
	1	`" "${label4b`p'}{it:`d`m'1`p''}" "'
	, angle(0) labsize(small)) 
	xtitle(" " "{bf:${party`p'}}" "{it:${var`p'}}" " ")
	ytitle("")
	ylab(, nogrid)
	xlab(-0.3(0.15)0.3)
	graphregion(color(white)) 
	legend(order(2 "Standardized Index" 4 "Standardized Weighted Index" "Anderson (2008)" 
	) 
	rows(2) size(*0.75) symxsize(*0.4))
	ylabel(, tlength(0))
	saving("$out/`m'`p'.gph", replace)
	;
	# delimit cr
	
}
}
*

*xsize(${width`p'}) ysize(5) 
# delimit ;
grc1leg "$out/m0.gph" "$out/m1.gph", 
	legendfrom("$out/m0.gph")
	graphregion(color(white)) 
	imargin(-5.5 -3 0 0) scale(1.1) 
	;
# delimit cr
graph export "$draftout/A7_Standardized_AnonymousMessage.eps", replace	
*	xsize(9) ysize(9)


# delimit ;
grc1leg "$out/ms0.gph" "$out/ms1.gph", 
	legendfrom("$out/ms1.gph")
	graphregion(color(white)) 
	imargin(-5.5 -3 0 0) scale(1.1) 
	;
# delimit cr
graph export "$draftout/A7_Standardized_Persuasion.eps", replace	
*	xsize(9) ysize(9)



